<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<c:set var="uploadPath" value="${redis:getSysConfig('uploadFileVisitRoot')}"/>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<style type="text/css">
	ul li{background: #f2f2f2;border-radius:2px 0px 0px 0px;}
</style>
<script type="text/javascript">

    /**通过商品父分类Id获取子分类集合**/
	function getSubCategoryListByParentId(parentId,selectId){
        $.ajax({
            type: "POST",
            dataType: "JSON",
            async:false,
            url: "${basePath}/back/productType/getSubCategoryListByParentId.sjson",
            data: {parentId:parentId},
            success: function(result){
                var sptList = result.sptList;
                var select_option_html="<option value='' selected='selected'>请选择</option>";
                for(var i=0;i<sptList.length;i++){
                    select_option_html+="<option value='"+sptList[i].productTypeId+"'>"+sptList[i].sortName+"</option>";
                }
                $("#"+selectId).empty().html(select_option_html);
                if(selectId=="category_level2"){//通过点击一级分类后重新开启二级和三级分类验证
                    reValidateField("category_level2");
                    $("#category_level3").empty().html("<option value='' selected='selected'>请选择</option>");
                    reValidateField("category_level3");
                }else{//通过点击二级分类后重新开启三级分类验证
                    reValidateField("category_level3");
                }
            }
        });

	}

    /**通过地区父分类Id获取子分类集合**/
    function getSubAreaListByParentId(parentId,selectId){
        $.ajax({
            type: "POST",
            dataType: "JSON",
            async:false,
            url: "${basePath}/back/area/getSubAreaListByParentId.sjson",
            data: {parentId:parentId},
            success: function(result){
                var areaList = result.areaList;
                var select_option_html="<option value='' selected='selected'>请选择</option>";
                for(var i=0;i<areaList.length;i++){
                    select_option_html+="<option value='"+areaList[i].areaId+"'>"+areaList[i].name+"</option>";
                }
                $("#"+selectId).empty().html(select_option_html);
            }
        });
        reValidateField("deliveryAddressCities");
    }

    /**通过店铺Id获取店铺商品内部分类集合**/
    function getShopProCategoryByShopInfoId(){
        $.ajax({
            type: "POST",
            dataType: "JSON",
            async:false,
            url: "${basePath}/back/shopProCategory/getShopProCategoryByShopInfoId.sjson",
            data: {shopInfoId:$("#shopInfoId").val()}, /**获取表单隐藏域中的店铺Id**/
            success: function(result){
                var shopProCategoryList = result.shopProCategoryList;
                var select_option_html="<option value='' selected='selected'>请选择</option>";
                for(var i=0;i<shopProCategoryList.length;i++){
                    select_option_html+="<option value='"+shopProCategoryList[i].shopProCategoryId+"'>"+shopProCategoryList[i].shopProCategoryName+"</option>";
                }
                $("#shopProCategoryId").empty().html(select_option_html);
            }
        });
    }

    /**通过商品Id获取商品和店铺内部分类的对象**/
    function getShopShopProCategoryRelationByProductId(productId){
        var shopProCategoryId="";
        $.ajax({
            type: "POST",
            dataType: "JSON",
            async:false,
            url: "${basePath}/back/shopProduct/getShopShopProCategoryRelationByProductId.sjson",
            data: {productId:productId}, /**获取表单隐藏域中的店铺Id**/
            success: function(result){
                var shopProCategoryRelation=result;
                shopProCategoryId=shopProCategoryRelation.shopProCategoryId;
            }
        });
        return shopProCategoryId;
    }

    /**关联显示分类下的品牌**/
    function showBrandListByProductTypeId(productTypeId){
        $.ajax({
            type: "POST",
            dataType: "JSON",
            async:false,
            url: "${basePath}/back/productType/getBrandListByProductTypeId.sjson",
            data: {productTypeId:productTypeId},
            success: function(result){
                var shopBrandList = result.shopBrandList;
                var select_option_html="<option value='' selected='selected'>请选择</option>";
                for(var i=0;i<shopBrandList.length;i++){
                    select_option_html+="<option value='"+shopBrandList[i].brandId+"'>"+shopBrandList[i].brandName+"</option>";
                }
                $("#brand_select").empty().html(select_option_html);
            }
        });
    }

    /**关联显示分类下的计量单位**/
    function showMeasuringUnitListByProductTypeId(productTypeId){
        $.ajax({
            type: "POST",
            dataType: "JSON",
            async:false,
            url: "${basePath}/back/productType/getMeasuringUnitListByProductTypeId.sjson",
            data: {productTypeId:productTypeId},
            success: function(result){
                var measuringUnitList = result.measuringUnitList;
                var select_option_html="<option value='' selected='selected'>请选择</option>";
                for(var i=0;i<measuringUnitList.length;i++){
                    select_option_html+="<option value='"+measuringUnitList[i].name.trim()+"'>"+measuringUnitList[i].name.trim()+"</option>";
                }
                $("#measuringUnit_select").empty().html(select_option_html);
            }
        });
    }

    /**显示分类下的关联的信息集合**/
    function showProductRelationInfoByProductTypeId(productTypeId){
        /**1、关联显示分类下的品牌**/
        showBrandListByProductTypeId(productTypeId);
        reValidateField("brandId");
        /**2、关联显示分类下的计量单位**/
        showMeasuringUnitListByProductTypeId(productTypeId);
        reValidateField("measuringUnitName");
        /**3、关联显示分类下的商品扩展属性，函数在attribute.jsp中**/
        showProductAttributeByProductTypeId(productTypeId);
        /**4、关联显示分类下的商品规格参数，parameter_info.jsp中**/
        showProductParameterByProductTypeId(productTypeId);
        /**5、关联显示分类下的商品规格组，specification_info.jsp中**/
        showProductSpecificationByProductTypeId(productTypeId);
    }

    /**修改商品时初始化商品基本信息**/
    function initProductInfo(productInfo){
        /**1、隐藏域**/
        $("#shopInfoId").val(productInfo.shopInfoId);/**店铺Id**/
        $("#productTypeId").val(productInfo.productTypeId);/**商品分类Id**/
        $("#productId").val(productInfo.productId);/**商品Id**/
        /**2、预览上传文件所需的信息，如果有上传图片功能添加此代码，否则可以去掉**/
        initImageForUpdate(1,"sys_shop","image_product",1,800,800,"${uploadPath}",productInfo.logoImg);
        $("#imageUrl_1").val(productInfo.logoImg);
        /**3、商品分类**/
        getSubCategoryListByParentId(0,"category_level1");/**回写商品一级分类**/
        $("#category_level1").find("option[value='"+productInfo.category_level1+"']").attr("selected",true);
        $("#category_level1").attr("disabled","disabled");/**不可编辑**/
        getSubCategoryListByParentId(productInfo.category_level1,"category_level2");/**回写商品二级分类**/
        $("#category_level2").find("option[value='"+productInfo.category_level2+"']").attr("selected",true);
        $("#category_level2").attr("disabled","disabled");/**不可编辑**/
        getSubCategoryListByParentId(productInfo.category_level2,"category_level3");/**回写商品三级分类**/
        $("#category_level3").find("option[value='"+productInfo.category_level3+"']").attr("selected",true);
        $("#category_level3").attr("disabled","disabled");/**不可编辑**/
        /**4、发货地**/
        getSubAreaListByParentId(0,"deliveryAddressProvince");/**回写省份地址**/
        $("#deliveryAddressProvince").find("option[value='"+productInfo.deliveryAddressProvince+"']").attr("selected",true);
        getSubAreaListByParentId(productInfo.deliveryAddressProvince,"deliveryAddressCities");/**回写城市地址**/
        $("#deliveryAddressCities").find("option[value='"+productInfo.deliveryAddressCities+"']").attr("selected",true);
        /**5、商品品牌**/
        showBrandListByProductTypeId(productInfo.category_level3);
        $("#brand_select").find("option[value='"+productInfo.brandId+"']").attr("selected",true);
        /**6、计量单位**/
        showMeasuringUnitListByProductTypeId(productInfo.category_level3);
        $("#measuringUnit_select").find("option[value='"+productInfo.measuringUnitName.trim()+"']").attr("selected",true);
        /**7、商品名称**/
        var productName=productInfo.productName;/**商品名称按照品牌名+" "+填写的商品名称组拼**/
        var subProductName=productName.substring(productName.indexOf(" "));
        $("#productName").val(subProductName.trim());
        /**8、店铺商品内部分类**/
        getShopProCategoryByShopInfoId();/**回写店铺内部分类**/
        var shopProCategoryId=getShopShopProCategoryRelationByProductId(productInfo.productId);/**获取已经和商品关联的店铺内部分类Id**/
        $("#shopProCategoryId").find("option[value='"+shopProCategoryId+"']").attr("selected",true);
        /**9、商品编号**/
        $("#productCode").val(productInfo.productCode);
        /**10、商品描述**/
        $("#describle").val(productInfo.describle);
        /**11、市场价格**/
        $("#marketPrice").val(productInfo.marketPrice);
        /**12、销售价格**/
        $("#salesPrice").val(productInfo.salesPrice);
        /**13、商品库存**/
        $("#storeNumber").val(productInfo.storeNumber);
        /**14、一级返利比例**/
        $("#upRatio").val(productInfo.upRatio);
        /**15、二级返利比例**/
        $("#secRatio").val(productInfo.secRatio);
        /**16、三级返利比例**/
        $("#thiRatio").val(productInfo.thiRatio);
        /**17、赠送金币**/
        $("#giveAwayCoinNumber").val(productInfo.giveAwayCoinNumber);
        /**18、商品重量**/
        $("#weight").val(productInfo.weight);
        /**19、包装规格**/
        $("#packingSpecifications").val(productInfo.packingSpecifications);
        /**20、条形码**/
        $("#barCode").val(productInfo.barCode);
        /**21、制造商型号**/
        $("#manufacturerModel").val(productInfo.manufacturerModel);
        /**22、商品备注**/
        $("#note").val(productInfo.note);
        /**23、SEO标题**/
        $("#seoTitle").val(productInfo.seoTitle);
        /**24、SEO关键字**/
        $("#seoKeyWord").val(productInfo.seoKeyWord);
        /**25、SEO描述**/
        $("#seoDescription").val(productInfo.seoDescription);
    }

</script>


<table  class="addOrEditTable table-bordered table" style="width:100%;">
	<tr>
		<th class="toright_td" rowspan="5"><span style="color:red">* </span>&nbsp;商品 Logo：</th>
		<td class="tocenter_td" rowspan="5" style="vertical-align: middle">
			<div class="container">
				<input id="imageUrl_1" type="hidden" name="logoImg" value=""/>
				<div class="form-group" id="fileWrap1"></div>
			</div>
			<span style="color:red;padding-top:5px;">提示：请上传规格宽800px，高800px的图片</span>
		</td>
		<th class="toright_td"><span style="color:red">* </span>&nbsp;商品分类：</th>
		<td class="toleft_td" width="265px" style="border-right: none;">
			<div class="form-group">
				<select class="form-control input-sm" id="category_level1" name="category_level1" onchange="getSubCategoryListByParentId(this.value,'category_level2')">
					<option value="">请选择</option>
				</select>
			</div>
		</td>
		<td class="toleft_td" style="border-right: none;border-left: none;">
			<div class="form-group">
				<select class="form-control input-sm" id="category_level2" name="category_level2" onchange="getSubCategoryListByParentId(this.value,'category_level3')">
					<option value="">请选择</option>
				</select>
			</div>
		</td>
		<td class="toleft_td" style="border-left: none;">
			<div class="form-group">
				<select class="form-control input-sm" id="category_level3" name="category_level3" onchange="showProductRelationInfoByProductTypeId(this.value)">
					<option value="">请选择</option>
				</select>
			</div>
		</td>
	</tr>
	<tr>
		<th class="toright_td"><span style="color:red">* </span>&nbsp;发货地：</th>
		<td  class="toleft_td" style="border-right: none">
			<div class="form-group">
				<select class="form-control input-sm" id="deliveryAddressProvince" name="deliveryAddressProvince"
						onchange="getSubAreaListByParentId(this.value,'deliveryAddressCities')">
					<option value="">请选择</option>
				</select>
			</div>
		</td>
		<td class="toleft_td" style="border-right: none;border-left: none;">
			<div class="form-group">
				<select class="form-control input-sm" id="deliveryAddressCities" name="deliveryAddressCities">
					<option value="">请选择</option>
				</select>
			</div>
		</td>
		<td style="border-left: none;"></td>
	</tr>
	<tr>
		<th class="toright_td"><span style="color:red">* </span>&nbsp;商品品牌：</th>
		<td class="toleft_td">
			<div class="form-group">
				<select class="form-control input-sm" id="brand_select" name="brandId">
					<option value="">请选择</option>
				</select>
			</div>
		</td>
		<th class="toright_td"><span style="color:red">* </span>&nbsp;商品计量单位：</th>
		<td class="toleft_td">
			<div class="form-group">
				<select class="form-control input-sm" id="measuringUnit_select" name="measuringUnitName">
					<option value="">请选择</option>
				</select>
			</div>
		</td>
	</tr>
	<tr>
		<th class="toright_td"><span style="color:red">* </span>&nbsp;商品名称：</th>
		<td class="toleft_td">
			<div class="form-group">
				<input type="text" class="form-control input-sm" id="productName" name="productName" placeholder="请输入商品名称"/>
			</div>
		</td>
		<th class="toright_td"><span style="color:red">* </span>&nbsp;店铺商品内部分类：</th>
		<td class="toleft_td">
			<div class="form-group">
				<select class="form-control input-sm" id="shopProCategoryId" name="shopProCategoryId">
					<option value="">请选择</option>
				</select>
			</div>
		</td>
	</tr>
	<tr>
		<th class="toright_td"><span style="color:red">* </span>&nbsp;商品编号：</th>
		<td class="toleft_td">
			<div class="form-group">
				<input type="text" class="form-control input-sm" id="productCode" name="productCode" placeholder="请输入商品编号"/>
			</div>
		</td>
		<th class="toright_td">&nbsp;商品描述：</th>
		<td class="toleft_td">
			<div class="form-group">
				<input type="text" class="form-control input-sm" id="describle" name="describle" placeholder="请输入商品描述"/>
			</div>
		</td>
	</tr>
	<tr>
		<th class="toright_td" width="200px"><span style="color:red">* </span>&nbsp;市场价格：</th>
		<td width="260px">
			<div class="form-group">
				<input type="text" class="form-control input-sm" id="marketPrice" name="marketPrice" placeholder="请输入市场价格"/>
			</div>
		</td>
		<th class="toright_td" width="260px"><span style="color:red">* </span>&nbsp;销售价格：</th>
		<td width="260px">
			<div class="form-group">
				<input type="text" class="form-control input-sm" id="salesPrice" name="salesPrice" placeholder="请输入销售价格"/>
			</div>
		</td>
		<th class="toright_td" width="260px"><span style="color:red">* </span>&nbsp;商品库存：</th>
		<td width="260px">
			<div class="form-group">
				<input type="text" class="form-control input-sm" id="storeNumber" name="storeNumber" placeholder="请输入商品库存"/>
			</div>
		</td>
	</tr>
	<tr>
		<th class="toright_td"><span style="color:red">* </span>&nbsp;一级返利比例：</th>
		<td>
			<div class="form-group">
				<input type="text" class="form-control input-sm" id="upRatio" name="upRatio" placeholder="请输入比例,如30表示30%">
			</div>
		</td>
		<th class="toright_td"><span style="color:red">* </span>&nbsp;二级返利比例：</th>
		<td>
			<div class="form-group">
				<input type="text" class="form-control input-sm" id="secRatio" name="secRatio" placeholder="请输入比例,如20表示20%"/>
			</div>
		</td>
		<th class="toright_td"><span style="color:red">* </span>&nbsp;三级返利比例：</th>
		<td>
			<div class="form-group">
				<input type="text" class="form-control input-sm" id="thiRatio" name="thiRatio" placeholder="请输入比例,如10表示10%"/>
			</div>
		</td>
	</tr>
	<tr>
		<th class="toright_td">&nbsp;赠送金币：</th>
		<td>
			<div class="form-group">
				<input type="text" class="form-control input-sm" id="giveAwayCoinNumber" name="giveAwayCoinNumber" placeholder="请输入赠送金币"/>
			</div>
		</td>
		<th class="toright_td"><span style="color:red">* </span>&nbsp;商品重量：</th>
		<td>
			<div class="form-group">
				<input type="text" class="form-control input-sm" id="weight" name="weight" placeholder="请输入商品重量,如50kg"/>
			</div>
		</td>
		<th class="toright_td"><span style="color:red">* </span>&nbsp;包装规格：</th>
		<td>
			<div class="form-group">
				<input type="text" class="form-control input-sm" id="packingSpecifications" name="packingSpecifications" placeholder="请输入包装规格,如100只/箱"/>
			</div>
		</td>
	</tr>
	<tr>
		<th class="toright_td">&nbsp;条形码：</th>
		<td>
			<div class="form-group">
				<input type="text" class="form-control input-sm" id="barCode" name="barCode" placeholder="请输入条形码"/>
			</div>
		</td>
		<th class="toright_td">&nbsp;制造商型号：</th>
		<td>
			<div class="form-group">
				<input type="text" class="form-control input-sm" id="manufacturerModel" name="manufacturerModel" placeholder="请输入制造商型号"/>
			</div>
			<input type="hidden" id="isChargeFreight" name="isChargeFreight" value="1" />
		</td>
		<th class="toright_td">&nbsp;商品备注：</th>
		<td>
			<div class="form-group">
				<input type="text" class="form-control input-sm" id="note" name="note" placeholder="请输入商品备注"/>
			</div>
		</td>
	</tr>
	<tr>
		<th class="toright_td">SEO标题：</th>
		<td>
			<div class="form-group">
				<input type="text" class="form-control input-sm" id="seoTitle" name="seoTitle" placeholder="请输入SEO标题"/>
			</div>
		</td>
		<th class="toright_td">SEO关键字：</th>
		<td>
			<div class="form-group">
				<input type="text" class="form-control input-sm" id="seoKeyWord" name="seoKeyWord" placeholder="请输入SEO关键字"/>
			</div>
		</td>
		<th class="toright_td">SEO描述：</th>
		<td>
			<div class="form-group">
				<input type="text" class="form-control input-sm" id="seoDescription" name="seoDescription" placeholder="请输入SEO描述"/>
			</div>
		</td>
	</tr>
</table>
